- /* spltlgfl.cpp by K.Tsuru */
- /*
- Split the decimal part of large number file in the form
- 3.+
- 1415...
-
- exsample large file name lines out file
- SplitLargeFile("ChudnovskysPi[1billion].dat", 1000000,"ChudPi%02d.dat");
- */
- #include <stdlib.h>
- #include <fstream>
- #include <string.h>
- using namespace std;
- int SplitLargeFile(const char* largeFileName, const long fileLineUnit, const char* outFNameFormat)
- {
- const int buffLength = 500;
- char splitFname[257], buff[buffLength];
- bool point = false; // decimal point
- ifstream read(largeFileName, ios::in);
- while(!point && !read.eof()) { // search point '.'
- read.getline(buff, buffLength, '\n');
- if(strchr(buff, '.')) point = true;
- }
- if(!point) return -1; // not decimal file
-
- ofstream fout;
- int fNo = 1, line = 1;
- while(!read.eof()) {
- sprintf(splitFname, outFNameFormat, fNo);
- fout.open(splitFname, ios::out);
- do { // write one block(a split file)
- read.getline(buff, buffLength, '\n');
- fout << buff << endl; line++;
- if(line > fileLineUnit){
- line = 1; fNo++;
- fout.close(); break;
- }
- } while(strlen(buff));
- }
- return fNo;
- }
-
spltlgfl.cpp : last modifiled at 2017/06/20 15:39:04(1,182 bytes)
created at 2017/10/03 15:04:05
The creation time of this html file is 2017/10/07 10:54:16 (Sat Oct 07 10:54:16 2017).